//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "ExponentialJump1dMesher.h"
using namespace Cephei::QL::Methods::Finitedifferences::Meshers;
#include <gen/QL/Methods/Finitedifferences/Meshers/Fdm1dMesher.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::CExponentialJump1dMesher (UInt64 steps, Double beta, Double jumpIntensity, Double eta, Microsoft::FSharp::Core::FSharpOption<Double>^ eps) : CFdm1dMesher(CExponentialJump1dMesher::typeid)
{
    try
    {
#ifdef HANDLE
        _phExponentialJump1dMesher = NULL;
#endif
        QuantLib::Size _steps = (QuantLib::Size)ValueHelper::Convert (steps); //d
        QuantLib::Real _beta = (QuantLib::Real)ValueHelper::Convert (beta); //d
        QuantLib::Real _jumpIntensity = (QuantLib::Real)ValueHelper::Convert (jumpIntensity); //d
        QuantLib::Real _eta = (QuantLib::Real)ValueHelper::Convert (eta); //d
        QuantLib::Real _eps = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (eps) ? (QuantLib::Real)ValueHelper::Convert (eps->Value) : 1e-3); //4
        _ppExponentialJump1dMesher = new boost::shared_ptr<QuantLib::ExponentialJump1dMesher> (new QuantLib::ExponentialJump1dMesher ( _steps,  _beta,  _jumpIntensity,  _eta,  _eps ));
        SetFdm1dMesher (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppExponentialJump1dMesher));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::CExponentialJump1dMesher (boost::shared_ptr<QuantLib::ExponentialJump1dMesher>& childNative, Object^ owner) : CFdm1dMesher(CExponentialJump1dMesher::typeid)
{
#ifdef HANDLE
	_phExponentialJump1dMesher = NULL;
#endif
	_ppExponentialJump1dMesher = &childNative;
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppExponentialJump1dMesher));
}
Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::CExponentialJump1dMesher (QuantLib::ExponentialJump1dMesher& childNative, Object^ owner) : CFdm1dMesher(CExponentialJump1dMesher::typeid)
{
#ifdef HANDLE
	_phExponentialJump1dMesher = NULL;
#endif
	_ppExponentialJump1dMesher = new boost::shared_ptr<QuantLib::ExponentialJump1dMesher> (&childNative);
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppExponentialJump1dMesher));
    _ExponentialJump1dMesherOwner = owner;
    _Fdm1dMesherOwner = owner;
}

Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::CExponentialJump1dMesher (CExponentialJump1dMesher^ copy) : CFdm1dMesher(CExponentialJump1dMesher::typeid)
{
#ifdef HANDLE
	_phExponentialJump1dMesher = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppExponentialJump1dMesher = new boost::shared_ptr<QuantLib::ExponentialJump1dMesher> (copy->GetShared());
        _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppExponentialJump1dMesher));
    }
}
Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::CExponentialJump1dMesher (PLATFORM::Type^ t) : CFdm1dMesher(CExponentialJump1dMesher::typeid)
{
#ifdef HANDLE
	_phExponentialJump1dMesher = NULL;
#endif
	if (!t->IsSubclassOf(CExponentialJump1dMesher::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::CExponentialJump1dMesher (QuantLib::Handle<QuantLib::ExponentialJump1dMesher>& childNative, Object^ owner)  : CFdm1dMesher(CExponentialJump1dMesher::typeid)
{
	_phExponentialJump1dMesher = &childNative;
	_ppExponentialJump1dMesher = &static_cast<boost::shared_ptr<QuantLib::ExponentialJump1dMesher>>(childNative.currentLink());
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppExponentialJump1dMesher));
    _ExponentialJump1dMesherOwner = owner;
}
Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::CExponentialJump1dMesher (QuantLib::Handle<QuantLib::ExponentialJump1dMesher> childNative)  : CFdm1dMesher(CExponentialJump1dMesher::typeid)
{
	_phExponentialJump1dMesher = &childNative;
	_ppExponentialJump1dMesher = &static_cast<boost::shared_ptr<QuantLib::ExponentialJump1dMesher>>(childNative.currentLink());
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppExponentialJump1dMesher));
}
#endif
#ifdef STRUCT
Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::CExponentialJump1dMesher (QuantLib::ExponentialJump1dMesher childNative)  : CFdm1dMesher(CExponentialJump1dMesher::typeid)
{
#ifdef HANDLE
	_phExponentialJump1dMesher = NULL;
#endif
	_ppExponentialJump1dMesher = new boost::shared_ptr<QuantLib::ExponentialJump1dMesher> (new QuantLib::ExponentialJump1dMesher (childNative));
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppExponentialJump1dMesher));
}
#endif

Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::~CExponentialJump1dMesher ()
{
    if (_ppExponentialJump1dMesher != NULL)
    {
	    delete _ppExponentialJump1dMesher;
        _ppExponentialJump1dMesher = NULL;
    }
}
Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::!CExponentialJump1dMesher ()
{
    if (_ppExponentialJump1dMesher != NULL)
    {
	    delete _ppExponentialJump1dMesher;
    }
}
QuantLib::ExponentialJump1dMesher& Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::GetReference ()
{
    if (_ppExponentialJump1dMesher == NULL) throw REFNEW NativeNullException ();
	return **_ppExponentialJump1dMesher;
}
boost::shared_ptr<QuantLib::ExponentialJump1dMesher>& Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::GetShared ()
{
    if (_ppExponentialJump1dMesher == NULL) throw REFNEW NativeNullException ();
	return *_ppExponentialJump1dMesher;
}
QuantLib::ExponentialJump1dMesher* Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::GetPointer ()
{
    if (_ppExponentialJump1dMesher == NULL) throw REFNEW NativeNullException ();
	return &**_ppExponentialJump1dMesher;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ExponentialJump1dMesher>& Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::GetHandle ()
{
	if (_phExponentialJump1dMesher == NULL)
	{
		_phExponentialJump1dMesher = new Handle<QuantLib::ExponentialJump1dMesher> (*_ppExponentialJump1dMesher);
	}
	return *_phExponentialJump1dMesher;
}
#endif
bool Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::HasNative () 
{
	return (_ppExponentialJump1dMesher != NULL);
}

Double Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::JumpSizeDensity (Double x, Double t)
{
    try
    {
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x); //a
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExponentialJump1dMesher)->jumpSizeDensity ( _x,  _t );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::JumpSizeDensity (Double x)
{
    try
    {
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExponentialJump1dMesher)->jumpSizeDensity ( _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::JumpSizeDistribution (Double x, Double t)
{
    try
    {
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x); //a
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExponentialJump1dMesher)->jumpSizeDistribution ( _x,  _t );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher::JumpSizeDistribution (Double x)
{
    try
    {
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExponentialJump1dMesher)->jumpSizeDistribution ( _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Methods::Finitedifferences::Meshers::IExponentialJump1dMesher^ Cephei::QL::Methods::Finitedifferences::Meshers::CExponentialJump1dMesher_Factory::Create (UInt64 steps, Double beta, Double jumpIntensity, Double eta, Microsoft::FSharp::Core::FSharpOption<Double>^ eps)
{
    return REFNEW CExponentialJump1dMesher ( steps,  beta,  jumpIntensity,  eta,  eps);
}
